//
//  BDFaceAirInterfaceViewController.m
//  MingJingSalesAssistant
//
//  Created by v_bihongvwei on 2021/12/31.
//

#import "BDFaceAirInterfaceViewController.h"
#import <BDFaceBaseKit/BDFaceBaseKit.h>
#import "BDFaceSelectRadio.h"
#import "BDFaceLiveSelectItemViewController.h"
#import "BDFaceLogoView.h"

static float const BDFaceAdjustParamsNavigationBarHeight = 44.0f;
static float const BDFaceAdjustParamsNavigationBarTitleLabelOriginX = 80.0f;
static float const BDFaceAdjustParamsNavigationBarBackButtonWidth = 60.0f;
static float const BDFaceAdjustConfigControllerTitleFontSize = 18.0f;
static float const BDFaceAdjustConfigContentTitleFontSize = 16.0f;

@interface BDFaceAirInterfaceViewController ()<UIGestureRecognizerDelegate>
@property(nonatomic, strong) UIButton *goBackButton;
@property(nonatomic, strong, readonly) UILabel *titleLabel;
@property(nonatomic, strong) UIView *titleView;
@property(nonatomic, strong) BDFaceSelectRadio *radio1;
@property(nonatomic, strong) BDFaceSelectRadio *radio2;
@property(nonatomic, strong) BDFaceSelectRadio *radio3;
@property(nonatomic, strong) UIButton *btn1;
@property(nonatomic, strong) UIButton *btn2;
@property(nonatomic, strong) UIButton *btn3;

@end

@implementation BDFaceAirInterfaceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = KColorFromRGBAlpha(0xF0F1F2, 1);
    [self loadTitleView];
    [self setUIConfig];
    UISwipeGestureRecognizer *recognizer;
    //right--
    recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
    [[self view] addGestureRecognizer:recognizer];
}

//手势返回
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
    if (recognizer.direction == UISwipeGestureRecognizerDirectionRight) {
        //执行程序
        [self.navigationController popViewControllerAnimated: YES];
    }
}

- (void)loadTitleView {
    CGFloat originY = [BDFaceCalculateTool safeTopMargin];
    if (originY == 0) {
        originY = 20.0f;
    }
    CGRect titleRect = CGRectMake(0, originY, ScreenWidth, BDFaceAdjustParamsNavigationBarHeight);
    self.titleView = [[UIView alloc] initWithFrame:titleRect];
    [self.view addSubview:self.titleView];
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(BDFaceAdjustParamsNavigationBarTitleLabelOriginX, 0, [BDFaceCalculateTool screenWidth] - BDFaceAdjustParamsNavigationBarTitleLabelOriginX * 2.0, BDFaceAdjustParamsNavigationBarHeight)];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    _titleLabel.text = @"云端接口设置";
    [self.titleView addSubview:_titleLabel];
    _titleLabel.font = [UIFont boldSystemFontOfSize:BDFaceAdjustConfigControllerTitleFontSize];
    self.goBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.goBackButton.frame = CGRectMake(0, 0, BDFaceAdjustParamsNavigationBarBackButtonWidth, CGRectGetHeight(self.titleView.frame));
    [self.titleView addSubview:self.goBackButton];
    [self.goBackButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    [self.goBackButton setImage:[UIImage imageNamed:@"icon_titlebar_back"] forState:UIControlStateNormal];
    self.goBackButton.imageView.contentMode = UIViewContentModeCenter;
    // 设置logo，底部的位置和大小，实例化显示
    BDFaceLogoView* logoView = [[BDFaceLogoView alloc] initWithFrame:CGRectMake(0, (ScreenHeight-32), ScreenWidth, 12)];
    [self.view addSubview:logoView];
}
-(void)setUIConfig{
    self.btn1 = [[UIButton alloc] init];
    self.btn1.tag = 101;
    self.btn1.backgroundColor = [UIColor whiteColor];
    self.btn1.frame = CGRectMake(16, KBDNaviHeight+24, ScreenWidth-32, 52);
    [self.btn1 yz_setRoundedWithCorners:UIRectCornerAllCorners cornerRadious:8];
    [self.btn1 addTarget:self action:@selector(btn1Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn1];
    self.radio1 = [BDFaceSelectRadio buttonWithType:UIButtonTypeCustom selected:NO];
    self.radio1.frame = CGRectMake(8, 6, 40, 40);
    [self.btn1 addSubview:self.radio1];
    UILabel *label1 = [[UILabel alloc] init];
    label1.textColor = [UIColor blackColor];
    label1.font = [UIFont systemFontOfSize:BDFaceAdjustConfigContentTitleFontSize];
    label1.frame = CGRectMake(44, 15, 100, 22);
    label1.textAlignment = NSTextAlignmentLeft;
    label1.text = @"人脸实名认证";
    [self.btn1 addSubview:label1];
    self.btn2 = [[UIButton alloc] init];
    self.btn2.tag = 102;
    self.btn2.backgroundColor = [UIColor whiteColor];
    self.btn2.frame = CGRectMake(16, KBDNaviHeight + 84, ScreenWidth - 32, 52);
    [self.btn2 yz_setRoundedWithCorners:UIRectCornerAllCorners cornerRadious:8];
    [self.btn2 addTarget:self action:@selector(btn2Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn2];

    self.radio2 = [BDFaceSelectRadio buttonWithType:UIButtonTypeCustom selected:NO];
    self.radio2.frame = CGRectMake(8, 6, 40, 40);
    [self.btn2 addSubview:self.radio2];

    UILabel *label2 = [[UILabel alloc] init];
    label2.textColor = [UIColor blackColor];
    label2.font = [UIFont systemFontOfSize:BDFaceAdjustConfigContentTitleFontSize];
    label2.frame = CGRectMake(44, 15, 100, 22);
    label2.textAlignment = NSTextAlignmentLeft;
    label2.text = @"人脸对比";
    [self.btn2 addSubview:label2];

    self.btn3 = [[UIButton alloc] init];
    self.btn3.tag = 103;
    self.btn3.backgroundColor = [UIColor whiteColor];
    self.btn3.frame = CGRectMake(16, KBDNaviHeight+24+60+60, ScreenWidth-32, 52);
    [self.btn3 yz_setRoundedWithCorners:UIRectCornerAllCorners cornerRadious:8];
    [self.btn3 addTarget:self action:@selector(btn3Action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn3];
    
    self.radio3 = [BDFaceSelectRadio buttonWithType:UIButtonTypeCustom selected:NO];
    self.radio3.frame = CGRectMake(8, 6, 40, 40);
    [self.btn3 addSubview:self.radio3];
    
    UILabel *label3 = [[UILabel alloc] init];
    label3.textColor = [UIColor blackColor];
    label3.font = [UIFont systemFontOfSize:BDFaceAdjustConfigContentTitleFontSize];
    label3.frame = CGRectMake(44, 15, 100, 22);
    label3.textAlignment = NSTextAlignmentLeft;
    label3.text = @"在线图片活体";
    [self.btn3 addSubview:label3];
    if (self.selectType == 1) {
        [self btn1Action];
    } else if (self.selectType == 2) {
        [self btn2Action];
    } else if (self.selectType == 3) {
        [self btn3Action];
    }
}

-(void)btn1Action{
    [self.radio1 changeRadioState:YES];
    [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"AirInterface"];
}

-(void)btn2Action{
    [self.radio2 changeRadioState:YES];
    [[NSUserDefaults standardUserDefaults] setInteger:2 forKey:@"AirInterface"];
}

-(void)btn3Action{
    [self.radio3 changeRadioState:YES];
    [[NSUserDefaults standardUserDefaults] setInteger:3 forKey:@"AirInterface"];
}

- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}
@end

